package com.xwaiy.xwaiyrpc.proxy;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author Xwaiy
 * @Date 2025/8/25 10:02
 **/
@Slf4j
public class MockServiceProxy implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 根据方法的返回值类型，生成特定的默认值对象
        Class<?> returnType = method.getReturnType();
        log.info("模拟调用:{}", method.getName());
        return getDefObject(returnType);
    }

    private Object getDefObject(Class<?> type) {
        // 基本类型
        if(type.isPrimitive()) {
            if(type.equals(int.class)) {
                return 0;
            }else if(type.equals(long.class)) {
                return 0L;
            }else if(type.equals(short.class)) {
                return (short)0;
            } else if (type.equals(boolean.class)) {
                return false;
            }
        }

        return null;
    }
}
